<?php
/**
 * #Celebrate Shieh
 *             ,%%%%%%%%,
 *           ,%%/\%%%%/\%%
 *          ,%%%\c "" J/%%%
 * %.       %%%%/ o  o \%%%
 * `%%.     %%%%    _  |%%%
 *  `%%     `%%%%(__Y__)%%'
 *  //       ;%%%%`\-/%%%'
 * ((       /  `%%%%%%%'
 *  \\    .'          |
 *   \\  /       \  | |
 *    \\/         ) | |
 *     \         /_ | |__
 *     (___________))))))) 攻城湿
 *
 *        _       _
 * __   _(_)_   _(_) __ _ _ __
 * \ \ / / \ \ / / |/ _` |'_ \
 *  \ V /| |\ V /| | (_| | | | |
 *   \_/ |_| \_/ |_|\__,_|_| |_|
 */

namespace App\Modules\Blog\Service;


use App\Models\Blog\Lists;
use App\Models\System\User;
use Illuminate\Http\Request;

class ListService
{

    use Service;

    /**
     * 获取菜单
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function ListIndexService( $request )
    {
        $where          = function ( $query ) use ( $request ) {
            $query->where('status', 1);
            $query->where('is_show', 1);
        };
        $select         = [ 'id', 'name', 'is_show', 'sort_order', 'status', ];
        $list[ 'list' ] = Lists::AllModel($where, [], $select);
        $list[ 'user' ] = User::FirstModel([ 'id' => $this->getCommon()->UserCommonService()->id ])->lists()->pluck('id');
        return data($list);
    }

    /**
     * 设置自己的菜单
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function ListUpdateService( $request )
    {
        User::FirstModel([ 'id' => $this->getCommon()->UserCommonService()->id ])->lists()->sync($request->input('list'));
        return data();
    }
}
